#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool isPrime(int num) {
    if (num <= 1) {
        return false;
    }
    for (int i = 2; i * i <= num; ++i) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int nearestPrime(int num) {
    if (isPrime(num)) {
        return num;
    }
    int lower = num - 1;
    int upper = num + 1;
    while (true) {
        if (isPrime(lower)) {
            return lower;
        }
        if (isPrime(upper)) {
            return upper;
        }
        --lower;
        ++upper;
    }
}

int main() {
    string input;
    getline(cin, input);

    vector<string> words;
    string currentWord;
    for (char c : input) {
        if (isspace(c)) {
            if (!currentWord.empty()) {
                words.push_back(currentWord);
                currentWord.clear();
            }
        } else {
            currentWord += c;
        }
    }
    if (!currentWord.empty()) {
        words.push_back(currentWord);
    }

    if (words.size() != 3) {
        cout << "Wrong input" << endl;
        return 0;
    }

    vector<int> digits;
    for (const string& word : words) {
        if (word == "zero") digits.push_back(0);
        else if (word == "one") digits.push_back(1);
        else if (word == "two") digits.push_back(2);
        else if (word == "three") digits.push_back(3);
        else if (word == "four") digits.push_back(4);
        else if (word == "five") digits.push_back(5);
        else if (word == "six") digits.push_back(6);
        else if (word == "seven") digits.push_back(7);
        else if (word == "eight") digits.push_back(8);
        else if (word == "nine") digits.push_back(9);
        else {
            cout << "Wrong input" << endl;
            return 0;
        }
    }

    int num = digits[0] * 100 + digits[1] * 10 + digits[2];
    if (num < 100 || num > 999) {
        cout << "Wrong input" << endl;
        return 0;
    }

    cout << nearestPrime(num) << endl;

    return 0;
    while True:
        if prime(lower):
            print(lower)
            return
        elif prime(upper):
            print(upper)
            return
        lower -= 1
        upper += 1

nums = input().strip()
closest_prime_number(nums)